﻿using System;

namespace Selection_Sort
{
    public static class SelectionSort
    {
        private static int[] array;

        public static int[] Sort(int[] arr)
        {
            array = arr;
            SelectionSortHelper();

            return array;
        }

        private static void SelectionSortHelper()
        {
            int smallest;

            for (int i = 0; i < array.Length - 1; ++i)
            {
                smallest = i;

                for (int index = i + 1; index < array.Length; ++index)
                    if ( array[index] < array[smallest])
                        smallest = index;

                Swap(i, smallest);               
            }
        }

        private static void Swap(int first, int second)
        {
            int temporary = array[first];
            array[first] = array[second];
            array[second] = temporary;
        }
    }
}
